package com.bean;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.dao.CommentSQL;

public class Comment {
	private int id;
	private String title;
	private String content;
	private int uid;
	private int bid;
	private int ccid;
	private List<Comment> list;
	private Timestamp time;

	public Comment(int id, String title, String content, int uid, int bid,int ccid, Timestamp time) {
		super();
		this.id = id;
		this.title = title;
		this.content = content;
		this.uid = uid;
		this.bid = bid;
		this.setCcid(ccid);
		this.time = time;
	}

	public Comment(String title, String content, int uid, int bid,int ccid) {
		super();
		this.title = title;
		this.content = content;
		this.uid = uid;
		this.bid = bid;
		this.ccid=ccid;
	}

	public Comment(int id, String title, String content, int uid,Timestamp time) {
		super();
		this.id = id;
		this.title = title;
		this.content = content;
		this.setUid(uid);
		this.time = time;
	}

	public Comment(String title, String content) {
		super();
		this.title = title;
		this.content = content;
	}

	public Comment(int id, String title, Timestamp time) {
		super();
		this.id = id;
		this.title = title;
		this.time = time;
	}

	public Comment() {
		// TODO Auto-generated constructor stub
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}



	public Timestamp getTime() {
		return time;
	}

	public void setTime(Timestamp time) {
		this.time = time;
	}


	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public int getBid() {
		return bid;
	}

	public void setBid(int bid) {
		this.bid = bid;
	}

	public int getCcid() {
		return ccid;
	}

	public void setCcid(int ccid) {
		this.ccid = ccid;
	}

	public List<Comment> getList() {
		return list;
	}
	public void setList(List<Comment> list){
		this.list=list;
	}
	public void setAllList(int id) {//获取关联的所有评论
		if(id==0)
			return;
		list=new ArrayList<Comment>();
		pullList(id,list);//回复过此id评论的所有评论
		Collections.sort(list, new SortByTime());
	}
	@Override
	public String toString() {
		return this.title;
	}

	public void setAllList(){
		setAllList(this.id);
	}
	public void pullList(int c,List<Comment> lit){
		if(c==0)
			return;
		ArrayList<Comment> lc=new CommentSQL().findByComment(c);
		for(int i=0;i<lc.size();i++){
			lit.add(lc.get(i));
			pullList(lc.get(i).getId(),lit);
		}
	}
	public static void main(String[] args) {
		Comment com=new Comment();
		com.setAllList(33);
		List list=com.getList();
		System.out.println(list.toString());
	}
}

class SortByTime implements Comparator<Comment>{

	@Override
	public int compare(Comment o1, Comment o2) {
		return o2.getTime().toString().compareTo(o1.getTime().toString());
	}

}
